package com.study.fastdfs;

import org.csource.common.NameValuePair;
import org.csource.fastdfs.*;

import java.io.File;
import java.io.IOException;

public class FastDfsUpload {

	private final static String GROUP = "group1";

	public static void main(String[] args) throws Exception {
		//group1/M00/64/09/wKgURFt7hueAW0rVAAAADSghvvI372.txt
		// 需要重新替换的文件名称
		String filePath = "ggg.png";
		File file = new File(filePath);
		// 使用MD5加密（经过验证，最多只支持16位后缀）
		ClientGlobal.init("fdfs_client.conf");
		System.out.println("ClientGlobal.configInfo(): " + ClientGlobal.configInfo());
		String uuid = MD5.MD5_16bit("---" + filePath);
		// 获取fdfs客户端
		StorageServer storageServer = null;
		TrackerClient tracker = new TrackerClient();
		TrackerServer trackerServer = tracker.getConnection();
		StorageClient client = new StorageClient(trackerServer,storageServer);
		// 重新上传新文件
		NameValuePair[] meta_list = new NameValuePair[2];
		System.out.println(uuid);
		meta_list[0] = new NameValuePair("fileName", file.getName());
		meta_list[1] = new NameValuePair("uuid", uuid);
//		String[] results = client.upload_file(GROUP, REMOTE_PATH_Image, uuid, file.getName(), "txt", meta_list);
//		System.out.println(GROUP.concat("/").concat(results[1]));



		String[] results  = client.upload_file(file.getName(), "png", null);
		System.out.println(GROUP.concat("/").concat(results[1]));
	}


}
